/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package JFreeChartExtensions.utils;

import java.io.File;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author Nobody
 */
public class DataFileFilter extends FileFilter {

    public final String[] extensions;
    public final String description;
    
    public DataFileFilter() {
        extensions = new String[1];
        extensions[0] = "csv";
        description = "Raw Data file (*.csv)";
    }

    public DataFileFilter(String ext) {
        this(new String[]{ext}, null);
    }

    public DataFileFilter(String[] exts, String descr) {
        extensions = new String[exts.length];
        for (int i = exts.length - 1; i >= 0; i--) {
            extensions[i] = exts[i].toLowerCase();
        }
        description = (descr == null ? exts[0] + " files" : descr);
    }

    @Override
    public boolean accept(File f) {
        if (f.isDirectory()) {
            return true;
        }

        String name = f.getName().toLowerCase();
        for (int i = extensions.length - 1; i >= 0; i--) {
            if (name.endsWith(extensions[i])) {
                return true;
            }
        }
        return false;
    }

    @Override
    public String getDescription() {
        return description;
    }
}
